package com.tianpengtech.admin.dictionary;


import com.tianpengtech.common.GlobalConfigConstant;
import com.tianpengtech.common.cache.CacheManager;
import com.tianpengtech.common.model.dictionary.Dictionary;
import com.tianpengtech.common.util.XxxUtil;

import java.util.List;
import java.util.Map;

public class DictionaryDao {

    public static final DictionaryDao ME = new DictionaryDao();

    public List<Dictionary> readParents(int code){

        String sql="select * from "+Dictionary.dao.tableName()+" where "+Dictionary.PID+"=?";
        return Dictionary.dao.find(sql,code);
    }


    public Dictionary readDirecotryByCode(long code){

        Map<String, Object> params = XxxUtil.createMapInstance();
        params.put("code", code);
        String cacheKey = CacheManager.buildCacheKey(GlobalConfigConstant.CACHENAME_ADMIN,
                "readDirecotryByCode", params);
        String sql="select * from "+Dictionary.dao.tableName()+" where "+Dictionary.CODE+"=?";
        return Dictionary.dao.findFirstByCache(GlobalConfigConstant.CACHENAME_ADMIN,cacheKey,sql,code);
    }
}
